home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #1 / Amiga Plus Extra 1997 #1.iso / programme / tools / wincloser / wincloser.c < prev    next >
C/C++ Source or Header  |  1996-11-25  |  3KB  |  137 lines

  1. ;/* Execute me to compile under SAS C 5.10...
  2. asm -iIncdir: iesupport.a
  3. lc wincloser
  4. BLink from LIB:c.o+wincloser.o+iesupport.o LIB LIB:lcs.lib LIB:amiga.lib TO WinCloser
  5. quit
  6. */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <exec/nodes.h>
  11. #include <devices/input.h>
  12. #include <intuition/intuition.h>
  13. #include <exec/interrupts.h>
  14. #include <proto/all.h>
  15.  
  16.  
  17. /*
  18.  * Defines and Structs...
  19.  */
  20. #define MYPORT "private.port"
  21.  
  22. struct PrivateMessage {
  23.     struct Message pm_Message;
  24.     char *TextPointer;
  25.     };
  26.  
  27.  
  28. /*
  29.  * Puny Prototypes...
  30.  */
  31. int CXBRK(void) { return(0); }
  32. int chkabort(void) { return(0); }
  33. struct MsgPort *SendMessage(void);
  34. void WaitForUser(void);
  35. extern VOID AlternateCloseWin();
  36.  
  37.  
  38. /*
  39.  * Version info...
  40.  */
  41. char *versioninfo="\0$VER: WindowCloser version 1.0\n";
  42.  
  43.  
  44. /*
  45.  * Meat and Potatoes... 
  46.  */
  47. void main(void)
  48. {
  49. struct IOStdReq  *inputReqBlk;
  50. struct MsgPort   *inputPort;
  51. struct Interrupt *inputHandler;
  52.  
  53. if(SendMessage())return;    /* If other copy running abort both... */
  54.  
  55.     if (inputPort=CreatePort(NULL,NULL))
  56.     {
  57.         if (inputHandler=AllocMem(sizeof(struct Interrupt),
  58.                                    MEMF_PUBLIC|MEMF_CLEAR))
  59.         {
  60.             if (inputReqBlk=(struct IOStdReq *)CreateExtIO(inputPort,
  61.                                                      sizeof(struct IOStdReq)))
  62.             {
  63.                 if (!OpenDevice("input.device",NULL,
  64.                                  (struct IORequest *)inputReqBlk,NULL))
  65.                 {
  66.                     inputHandler->is_Code=AlternateCloseWin;
  67.                     inputHandler->is_Data=NULL;
  68.                     inputHandler->is_Node.ln_Pri=100;
  69.                     inputHandler->is_Node.ln_Name="BSIWindowCloser";
  70.                     inputReqBlk->io_Data=(APTR)inputHandler;
  71.                     inputReqBlk->io_Command=IND_ADDHANDLER;
  72.                     DoIO((struct IORequest *)inputReqBlk);
  73.  
  74.                     WaitForUser();
  75.  
  76.                     inputReqBlk->io_Data=(APTR)inputHandler;
  77.                     inputReqBlk->io_Command=IND_REMHANDLER;
  78.                     DoIO((struct IORequest *)inputReqBlk);
  79.  
  80.                     CloseDevice((struct IORequest *)inputReqBlk);
  81.                 }
  82.                 DeleteExtIO((struct IORequest *)inputReqBlk);
  83.             }
  84.             FreeMem(inputHandler,sizeof(struct Interrupt));
  85.         }
  86.         DeletePort(inputPort);
  87.     }
  88. }
  89.  
  90.  
  91. /*
  92.  * This Waits for the user...
  93.  */
  94. void WaitForUser(void) {
  95.  
  96. struct MsgPort *export;
  97. struct PrivateMessage *messy;
  98.  
  99. if(export=CreatePort(MYPORT,NULL)) {
  100.  
  101. for(;;) {
  102.     WaitPort(export);
  103.     if(messy=(struct PrivateMessage *)GetMsg(export))break;
  104.     }
  105. ReplyMsg((struct Message *)messy);
  106. DeletePort(export);}
  107. }
  108.  
  109.  
  110. /*
  111.  * SendMessage
  112.  */
  113. struct MsgPort *SendMessage(void) {
  114.  
  115. struct MsgPort *export,*inport;
  116. struct PrivateMessage *mymessage;
  117. char *samplemess="WindowCloser(w)1993 BSI";
  118.  
  119. Forbid();
  120. if(export=FindPort(MYPORT)) {
  121. if(mymessage=AllocMem(sizeof(struct PrivateMessage),MEMF_PUBLIC|MEMF_CLEAR)){
  122. if(inport=CreatePort(NULL,NULL)){
  123. mymessage->pm_Message.mn_Node.ln_Type=NT_MESSAGE;
  124. mymessage->pm_Message.mn_Length=sizeof(struct PrivateMessage);
  125. mymessage->pm_Message.mn_ReplyPort=inport;
  126. mymessage->TextPointer=samplemess;
  127.  
  128. PutMsg(export,(struct Message *)mymessage);
  129. WaitPort(inport);
  130.  
  131. DeletePort(inport);}
  132. FreeMem(mymessage,sizeof(struct PrivateMessage));}
  133. Permit();
  134. return(export);
  135. }
  136. }
  137.